$(function(){
    getAllData();
    $('#searchbtn').click(function(){
        let val=$('#search').val();
        console.log(val);
        if(val.trim()==""){
          return;
        }
        let arr=[];
        let keyword=localStorage.getItem('keyword');
        if(keyword !=null){
            arr=JSON.parse(keyword);
        }
        arr.unshift(val);
        localStorage.setItem('keyword',JSON.stringify(arr));
        $('#search').val("");
        
   
      getAllData();
    });
})

function getAllData(){
    let keyword=localStorage.getItem('keyword');
    let arr=[];
    if(keyword!=null){
        arr=JSON.parse(keyword);
    }
    let str='';
    for(let i=0;i<arr.length;i++){
        str += `<span>${ arr[i]}</span>`;
    }
    $(".listbox").html(str);
}

$('#delbtn').click(function(){
    if(confirm('你确定删除吗?')){
        localStorage.clear();
        $('.listbox').html('');
    }
})